package rss_POJO;

import java.util.Collection;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author RS-team
 */
@Entity
@Table(name = "MUSICPRODUCTIONCOMPANY")
//@Table(name = "MUSICPRODUCTIONCOMPANY", uniqueConstraints = {
//    @UniqueConstraint(columnNames = {"NAME"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MusicProductionCompany.findAll", query = "SELECT m FROM MusicProductionCompany m"),
    @NamedQuery(name = "MusicProductionCompany.findByMpcompanyid", query = "SELECT m FROM MusicProductionCompany m WHERE m.mpcompanyid = :mpcompanyid"),
    @NamedQuery(name = "MusicProductionCompany.findByName", query = "SELECT m FROM MusicProductionCompany m WHERE m.name = :name"),
    @NamedQuery(name = "MusicProductionCompany.findByAddress", query = "SELECT m FROM MusicProductionCompany m WHERE m.address = :address"),
    @NamedQuery(name = "MusicProductionCompany.findByTelephone", query = "SELECT m FROM MusicProductionCompany m WHERE m.telephone = :telephone")})
public class MusicProductionCompany implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "MPCOMPANYID")  // είναι not nullable αλλά και unique ως primary key
        @Basic(optional = false)
        private Integer mpcompanyid;
    @Column(name = "NAME", nullable = false, unique = true, length = 100)  // μοναδικότητα κύριου αναγνωριστικού πεδίου αναζήτησης
        @Basic(optional = false)
        private String name;
    @Column(name = "ADDRESS", nullable = true, unique = false, length = 100)
        @Basic(optional = true)
        private String address;
    @Column(name = "TELEPHONE", nullable = true, unique = false, length = 50)
        @Basic(optional = true)
        private String telephone;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "mpcompanyId")
        private Collection<Album> albumCollection;

    /* default constructor */
    public MusicProductionCompany() {
    }
    /* "τεμπέλικος" constructor χωρίς τα nullable πεδία */
    public MusicProductionCompany(String name) {
        this.mpcompanyid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.name = name;
    }
    /* και ο πλήρης constructor */
    public MusicProductionCompany(String name, String address, String telephone) {
        this.mpcompanyid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.name = name;
        this.address = address;
        this.telephone = telephone;
    }

    /* getters */
    public Integer getMpcompanyid() { return mpcompanyid; }
    public String getName() { return name; }
    public String getAddress() { return address; }
    public String getTelephone() { return telephone; }

    /* setters εκτός από το primary key */
    //public void setMpcompanyid(Integer mpcompanyid) { this.mpcompanyid = mpcompanyid; }
    public void setName(String name) { this.name = name; }
    public void setAddress(String address) { this.address = address; }
    public void setTelephone(String telephone) { this.telephone = telephone; }

    @XmlTransient
    /* getter και setter για την albumCollection */
    public Collection<Album> getAlbumCollection() {
        return albumCollection;
    }
    public void setAlbumCollection(Collection<Album> albumCollection) {
        this.albumCollection = albumCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (mpcompanyid != null ? mpcompanyid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MusicProductionCompany)) {
            return false;
        }
        MusicProductionCompany other = (MusicProductionCompany) object;
        if ((this.mpcompanyid == null && other.mpcompanyid != null) || (this.mpcompanyid != null && !this.mpcompanyid.equals(other.mpcompanyid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "rss_POJO.MusicProductionCompany[ mpcompanyid=" + mpcompanyid + " ]";
    }
    
}